package com.qn.visitor.config;

import com.qn.visitor.resources.ResourcesCore;
import com.qn.visitor.utils.IoUtils;
import org.lionsoul.ip2region.xdb.Searcher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.io.InputStream;
/**
 * qingniu-cloud user source analysis
 *
 * @Author: TXG
 * @Date: 2024/6/11
 * @Version V0.0.2
 */
@Configuration
public class Ip2RegionConfig {
   @Bean
   public Searcher ip2regionSearcher()
   {
      try (InputStream inputStream = Ip2RegionConfig.class.getClassLoader()
              .getResourceAsStream(ResourcesCore.IP2REGION_FILE_PATH)) {
         return Searcher.newWithBuffer(IoUtils.toByteArray(inputStream) );
      } catch (IOException ex) {
         ex.printStackTrace();
      }
      return null;
   }
}
